package com.zjw.springboot.test;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import java.net.URL;

/**
 * @author zhengjw
 * @version 2018/4/20 11:45
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class FullTestController {

    @LocalServerPort
    private int port;

    private URL base;

    @Autowired
    private TestRestTemplate testRestTemplate;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Before
    public void before() throws Exception{
        this.base = new URL("http://localhost:"+port+"/");
    }

    @Test
    public void getHello() {
        ResponseEntity<String> response = testRestTemplate.getForEntity(base.toString(), String.class);
        String expect = "hello, spring-boot!zjw";
        System.out.println(response.getBody());
    }

    @Test
    public void test00() {

        ResponseEntity<String> response = testRestTemplate.getForEntity(base.toString(), String.class);
        logger.info(response.getBody());
    }

    @Test
    public void test01() {

        logger.info("have a test !");
    }
}
